using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using PlanetTelex.Coverflow.Models;

namespace PlanetTelex.Coverflow 
{
    public class Migrations : DataMigrationImpl 
    {
        /// <summary>
        /// This executes whenever this module is activated.
        /// </summary>
        public int Create() 
        {
			// Creating table CoverflowRecord
			SchemaBuilder.CreateTable("CoverflowRecord", table => table
				.ContentPartRecord()
                .Column<string>("BasePath", column => column.WithLength(800))
                .Column<string>("SettingsJson", column => column.WithLength(1600))
			);

            ContentDefinitionManager.AlterPartDefinition(
                typeof(CoverflowPart).Name, cfg => cfg.Attachable());
            
            return 1;
        }

        public int UpdateFrom1()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(CoverflowPart).Name, builder => builder
                .WithDescription("An iTunes style coverflow that displays images from a media library folder."));

            return 2;
        }

        public int UpdateFrom2()
        {
            ContentDefinitionManager.AlterTypeDefinition("CoverflowWidget", cfg => cfg
                .WithPart("CoverflowPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));

            return 3;
        }
    }
}